<template>
    <view :class="[
      'diy-page',
      useNav ? 'useFoot' : '',
      showGoodsShare ? 'no-scroll' : ''
    ]" v-if="page">
        <view class="diy-page-bg" :style="[pageCss]"></view>
        <template v-if="goodsInfo">
            <template v-if="goodsInfo.product_type === 7">
                <u-sticky :h5NavHeight="0">
                    <singleHeader pageTitle="商品详情"></singleHeader>
                </u-sticky>

                <view class="template-section" v-for="(item, index) in showTemplate" :key="index" :id="item.comName">
                    <!-- 轮播图及头部导航 -->
                    <showGodsSwiperImgs v-if="item.comName == 'showGodsSwiperImgs' && item.params.show"
                        :goodsInfo="goodsInfo" :propsData="item"></showGodsSwiperImgs>

                    <showGoodsInfo v-if="item.comName == 'showGodsInfo'" :propsData="item" :goodsInfo="goodsInfo"
                        @shareGood="showGoodsShare = !showGoodsShare" @collect="collect"></showGoodsInfo>

                    <showGoodsContent v-if="item.comName == 'showGoodsContent'" :goodsInfo="goodsInfo"
                        :propsData="item"></showGoodsContent>

                    <template v-if="item.comName == 'showGoodsFootNav' && item.params.showBtn">
                        <view :class="[
                'footerNav',
                item.params.styleType == '1' ? 'round' : ''
              ]">
                            <!-- #ifdef MP-TOUTIAO -->
                            <button v-if="['', 'jump_douyin'].includes(item.params.link.open_type)"
                                open-type="openAwemeUserProfile" :data-aweme-id="goodsInfo.aweme_id"
                                @openawemeuserprofile="openawemeuserprofile" @click="hasVersion('2.92.0')" :style="{
                  background: item.params.btnColor
                }">
                                {{ item.params.btnText }}
                            </button>
                            <!-- #endif -->
                            <button v-if="item.params.link.open_type == 'goodsForm'" @click="
                  $utils.toUrl(
                    `${item.params.link.link}?goods_id=${goodsInfo.id}`
                  )
                " :style="{
                  background: item.params.btnColor
                }">
                                {{ item.params.btnText }}
                            </button>
                            <button v-if="
                  !['', 'jump_douyin', 'goodsForm'].includes(
                    item.params.link.open_type
                  )
                " @click="
                  $utils.toUrl(
                    `${item.params.link.link}`,
                    item.params.link.open_type
                  )
                " :style="{
                  background: item.params.btnColor
                }">
                                {{ item.params.btnText }}
                            </button>
                        </view>
                    </template>
                </view>
            </template>
            <template v-else>
                <view class="template-section" v-for="(item, index) in templates" :key="index" :id="item.comName">
                    <!-- 轮播图及头部导航 -->
                    <goodsSwiper v-if="item.comName == 'goodsSwiperImgs'" :goodsInfo="goodsInfo" :propsData="item"
                        :hideTopTab="hideTopTab" :topTabActiveIndex="topTabActiveIndex" @scrollToNode="scrollToNode"
                        :newData="newData" :timeDifference="timeDifference"></goodsSwiper>

                    <!-- 秒杀头部 -->
                    <view v-if="!index && goodsInfo.seckill_activity_arr" class="seckill">
                        <image class="seckillBg" lazy-load :src="asyncImgs.goods.seckill_bg" mode="aspectFill" />

                        <view class="seckillCon">
                            <view class="let">
                                <view class="price1">
                                    <view>{{ getSeckillPrice(getSeckillPriceOld)[0] }}</view>
                                    .{{ getSeckillPrice(getSeckillPriceOld)[1] }}
                                </view>
                                <view class="price2">￥{{ goodsInfo.seckill_activity_arr.price }}</view>
                                <view class="num" v-if="parseInt(goodsInfo.seckill_activity_arr.self_limit_num)">
                                    限购{{
                    parseInt(goodsInfo.seckill_activity_arr.self_limit_num)
                  }}件</view>
                            </view>
                            <view class="rig">
                                <view class="countDown">
                                    <view class="s1">{{
                    countDown[4] ? "距开始" : "距结束"
                  }}</view>
                                    <view class="s2">{{ countDown[0] }}天{{ countDown[1] }}:{{
                      countDown[2]
                    }}:{{ countDown[3] }}</view>
                                </view>
                                <view class="line">
                                    <view class="lineBox" :style="[
                      {
                        width:
                          (goodsInfo.seckill_activity_arr.progress || 0) + '%'
                      }
                    ]"></view>
                                    <view class="lineCon">已抢{{
                      goodsInfo.seckill_activity_arr === 2
                        ? 0
                        : parseInt(goodsInfo.seckill_activity_arr.sale_num) +
                          parseInt(
                            goodsInfo.seckill_activity_arr.virtual_sales
                          ) +
                          (parseInt(
                            goodsInfo.seckill_activity_arr.seckill_num
                          ) > 0
                            ? 0
                            : parseInt(
                                goodsInfo.seckill_activity_arr.virtual_num
                              ))
                    }}/限{{
                      parseInt(goodsInfo.seckill_activity_arr.sale_num) +
                      parseInt(goodsInfo.seckill_activity_arr.seckill_num) +
                      parseInt(goodsInfo.seckill_activity_arr.virtual_sales) +
                      parseInt(goodsInfo.seckill_activity_arr.virtual_num)
                    }}</view>
                                </view>
                            </view>
                        </view>
                    </view>

                    <!-- 群价格 -->
                    <view v-if="!index && goodsInfo.activityWechatRoom" class="seckill">
                        <image class="seckillBg" lazy-load src="../../static/images/goods-group-price-header.png"
                            mode="aspectFill" />

                        <view class="seckillCon">
                            <view class="let" style="align-items: flex-end">
                                群友特享价
                                <view class="price1">
                                    <view>{{
                    getSeckillPrice(goodsInfo.activityPrice || 0)[0]
                  }}</view>.{{ getSeckillPrice(goodsInfo.activityPrice || 0)[1] }}
                                </view>
                                <view class="price2">￥{{ goodsInfo.price }}</view>
                            </view>
                            <view class="rig">
                                <view class="countDown" style="flex-direction: column">
                                    <view class="s1">距活动结束</view>
                                    <view class="s2 u-m-t-10" style="margin-left: 0">
                                        <u-count-down :timestamp="goodsInfo.activityWechatRoom.inTime || 0"
                                            :show-seconds="false" separator-color="#ffffff" color="#f0250e"
                                            font-size="26" separator="zh"></u-count-down>
                                    </view>
                                </view>
                            </view>
                        </view>
                    </view>

                    <!-- 商品介绍 -->
                    <goodsIntroduce v-if="item.comName == 'goodsIntroduce'" :propsData="item" :goodsInfo="goodsInfo"
                        :is_pt="is_pt" :cutOrder="cutOrder" :activityCutPriceId="activity_cut_price_id"
                        @shareGood="showGoodsShare = !showGoodsShare" @collect="collect" @lowering="lowering"
                        @goPriceReduction="goPriceReduction"></goodsIntroduce>
                    <!-- 商品活动优惠 -->
                    <goodsDiscount v-if="
              item.comName == 'goodsDiscount' &&
              (couponList.length || cardList.length)
            " :propsData="item" :goodsInfo="goodsInfo" :couponList="couponList" :cardList="cardList"
                        @showCoupon="couponPopupShow" @showActive="activePopupShow"></goodsDiscount>

                    <!-- 溯源 -->
                    <view class="" v-if="goodsInfo.have_product_traceability == 1 && index == 0"
                        style="margin: 0 0 12px 0; position: relative; overflow: hidden">
                        <view class="" style="
                background-color: #ffffff;
                background-image: ;
                background-repeat: no-repeat;
                background-size: 100% 100%;
                opacity: 100;
                width: 100%;
                left: 10px;
                border-radius: 25rpx;
              ">
                            <view class="" style="width: 100%; padding: 4.8vw 0 4.8vw 4.8%">
                                <view class="" style="
                    width: 100%;
                    display: flex;
                    align-items: center;
                    padding-right: 4.8vw;
                  " @click="get_history">
                                    <view class="" style="
                      width: 82rpx;
                      font-size: 26rpx;
                      font-weight: 600;
                      color: #262626;
                    ">
                                        溯源
                                    </view>
                                    <view class="" style="
                      width: 100%;
                      display: flex;
                      align-items: center;
                      padding-right: 4.8vw;
                    ">
                                        该商品支持<text style="color: #f1270c">正版溯源</text>
                                    </view>
                                    <i class="iconfont icon-arrow-right" style="
                      font-size: 22rpx;
                      font-style: normal;
                      -webkit-font-smoothing: antialiased;
                      -moz-osx-font-smoothing: grayscale;
                    "></i>
                                </view>
                            </view>
                        </view>
                    </view>

                    <!-- 商品属性、运费、送至 -->
                    <goodsAttribute v-if="item.comName == 'goodsAttribute' && addressList &&shopmsg.product_type!=1"
                        ref="goods_sku"  :propsData="item" :goodsInfo="goodsInfo" :skuText="skuText" :mdId="mdId"
                        :mdData="mdData" :addressList="addressList" :activityCutPriceId="activity_cut_price_id"
                        :is_seckill="is_seckill" @chooseSku="selectSku" @gotoAddressList="gotoMyAddress">
                    </goodsAttribute>

                    <GoodsPt @onClickPt="onClickPt" v-if="item.comName == 'goodsPt' && goodsInfo.pt_activity && is_pt"
                        :goodsInfo="goodsInfo"></GoodsPt>

                    <!-- 商品评价 -->
                    <goodsEvaluate v-if="item.comName == 'goodsEvaluate'" :propsData="item" :goodsInfo="goodsInfo">
                    </goodsEvaluate>

                    <!-- 推荐商品 -->
                    <goodsRecommend v-if="item.comName == 'goodsRecommend'"></goodsRecommend>

                    <!-- 新增进店 -->
                    <view class="storeNext" v-if="item.comName == 'goodsRichText'&&mch!=null">
                        <view class="bg">
                            <u-image shape="circle" width="100rpx" height="100rpx" :src="mch.logo"></u-image>
                            <view class="content">
                                <view class="name">
                                    {{mch.name}}
                                </view>
                                <view class="address">
                                    {{mch.address}}
                                </view>
                            </view>
                            <view @click="goStore()" class=""
                                style="flex-grow: 1; display: flex;justify-content: flex-end;">
                                <view class="btn">
                                    进店
                                </view>
                            </view>
                        </view>
                    </view>

                    <!-- 商品详情富文本 -->
                    <goodsRichText v-if="item.comName == 'goodsRichText'" :goodsInfo="goodsInfo"></goodsRichText>
                    <!-- 底部导航 -->


                    <template v-if="item.comName == 'goodsFootNav'">
                        <goodsFootNav v-if="!activity_cut_price_id" :propsData="item" :goodsInfo="goodsInfo"
                            :is_pt="is_pt" :is_seckill="is_seckill" :pt_number="pt_number" @addCart="addCart"
                            @buyNow="rightBuy" @clickYuyue="clickYuyue" @onPt="onPt" @onGroup="onGroup"></goodsFootNav>
                        <goodsFootCutPriceNav v-else :propsData="item" :goodsInfo="goodsInfo" :cutOrder="cutOrder"
                            @addCart="addCart" @buyNow="rightBuy" @clickYuyue="clickYuyue"></goodsFootCutPriceNav>
                    </template>
                </view>

                <!-- sku弹框 -->
                <newSkuPopup v-if="templates.length" ref="skuPopup" :finalmsg="finalmsg" :shopmsg="shopmsg"
                    :subIndex="subIndex" :shopimg="shopimg" :diyTemplates="templates" :ptId="ptId"
                    :activityCutPriceId="activity_cut_price_id" :is_seckill="is_seckill" @closeSkuPopup="closeSkuPopup"
                    @selectPushData="selectPushData" @setSelectNum="setSelectNum" @buyNow="confirmBuy"></newSkuPopup>

                <!-- 送至弹框 -->
                <sendPopup ref="sendPopup" :addressList="addressList" @selectAddressEnd="selectAddressEnd"></sendPopup>

                <!-- 优惠券弹框 -->
                <couponPopup :popupTitle="$t('goods.discountTitle')" ref="couponPopup" v-if="couponList.length"
                    :couponList="couponList" :cardData="goodsInfo.verify_card_id"></couponPopup>

                <!-- 活动tank -->
                <cardPopup ref="activePopup" v-if="goodsInfo.verify_card_id.length"
                    :cardData="goodsInfo.verify_card_id"></cardPopup>

                <!-- 酒店预约弹框 -->
                <HotelPopup v-if="shopmsg && shopmsg.product_type == 1" :hotelData="hotelData" :diyTemplates="templates"
                    @pageDataChange="hotelDataChange" @submitHotel="submitHotel"></HotelPopup>
                <!-- 服务预约弹框 -->
                <ServePopup ref="ServePopup" v-if="shopmsg && shopmsg.product_type == 2" :serveData="serveData"
                    :diyTemplates="templates" @pageDataChange="serveDataChange" @submit="serveSubmit"></ServePopup>

                <!-- 时间日历选择 -->
                <timePopup v-if="shopmsg" :serveData="serveData" :hotelData="hotelData"
                    :product_type="shopmsg.product_type" @timeConfirm="timeConfirm" ref="timePopup"></timePopup>

                <GroupPromptPopup ref="GroupPromptPopup" @confirm="groupShowConfirm"></GroupPromptPopup>
            </template>
        </template>

        <!-- #ifndef MP-ALIPAY -->
        <controls :controlList="controlList"></controls>
        <!-- #endif -->

        <!-- 分享 -->
        <goodsShare v-if="showGoodsShare" :topic_id="goodsInfo.id" :is_seckill="is_seckill" :is_pt="is_pt"
            @closeShare="showGoodsShare = false">
        </goodsShare>
    </view>
</template>

<script>
    import controls from "@/components/diyNew/controls/index.vue";
    import goodsSwiper from "@/goods/diySystemPage/goodsDetail/goodsSwiper/index.vue";
    import goodsIntroduce from "@/goods/diySystemPage/goodsDetail/goodsIntroduce/index.vue";
    import goodsDiscount from "@/goods/diySystemPage/goodsDetail/goodsDiscount/index.vue";
    import goodsAttribute from "@/goods/diySystemPage/goodsDetail/goodsAttribute/index.vue";
    import goodsEvaluate from "@/goods/diySystemPage/goodsDetail/goodsEvaluate/index.vue";
    import goodsShopEntry from "@/goods/diySystemPage/goodsDetail/goodsShopEntry/index.vue";
    import goodsFootNav from "@/goods/diySystemPage/goodsDetail/goodsFootNav/index.vue";
    import goodsRichText from "@/goods/diySystemPage/goodsDetail/goodsRichText/index.vue";
    import goodsRecommend from "@/goods/diySystemPage/goodsDetail/goodsRecommend/index.vue";
    import goodsFootCutPriceNav from "@/goods/diySystemPage/goodsDetail/goodsFootCutPriceNav/index";

    import GoodsPt from "@/goods/diySystemPage/goodsDetail/goods-pt";

    import goodsShare from "./components/goodsShare.vue";
    // 酒店预订弹框
    import HotelPopup from "@/goods/goods/components/hotel-popup.vue";
    // 预订详情选择弹框
    import ServePopup from "@/goods/goods/components/serve-popup.vue";

    import newSkuPopup from "./components/skuPopup.vue";
    import sendPopup from "./components/sendPopup.vue";
    import couponPopup from "./components/couponPopup.vue";
    import activePopup from "./components/activePopup.vue";
    import cardPopup from "./components/cardPopup.vue";
    import timePopup from "./components/timePopup.vue";
    import GroupPromptPopup from "./components/GroupPromptPopup.vue";

    import singleHeader from "@/components/diySystemPage/components/singleHeader/index.vue";
    import showGodsSwiperImgs from "./showGodsSwiperImgs/index.vue";
    import showGoodsInfo from "./showGoodsInfo/index.vue";
    import showGoodsContent from "./showGoodsContent/index.vue";
    let timer = null;
    let timers = null;

    export default {
        props: {
            activity_new_user_id: {
                type: [String, Number],
                default: ""
            },
            activity_cut_price_id: {
                type: [String, Number],
                default: ""
            },
            goods_id: {
                type: String,
                default: ""
            },
            mdId: {
                type: String,
                default: "0"
            },
            mdData: {
                type: Object,
                default: {}
            },
            pageScrollTop: {
                type: Number,
                default: 0
            },
            hideTopTab: {
                type: Boolean,
                default: true
            },
            topTabActiveIndex: {
                type: Number,
                default: 0
            },
            videoId: {
                type: Number,
                default: 0
            },
            is_pt: {
                type: [String, Boolean],
                default: false
            },
            cutOrder: {
                type: Object,
                default () {
                    return null;
                }
            },
            is_seckill: {
                type: [String, Number],
                default: ""
            },
            pt_number: {
                type: [String, Number],
                default: 0
            },
            date: {
                type: String,
                default: ""
            },
            clearTimer: Boolean, // 接收清除定时器的标识
        },
        components: {
            controls,
            goodsSwiper,
            goodsIntroduce,
            goodsDiscount,
            goodsAttribute,
            goodsEvaluate,
            goodsShopEntry,
            goodsFootNav,
            goodsRichText,
            goodsRecommend,
            goodsShare,
            GoodsPt,
            HotelPopup,
            ServePopup,
            sendPopup,
            couponPopup,
            activePopup,

            newSkuPopup,
            cardPopup,
            timePopup,

            goodsFootCutPriceNav,
            GroupPromptPopup,

            singleHeader,
            showGodsSwiperImgs,
            showGoodsInfo,
            showGoodsContent
        },
        data() {
            return {
                currentTimestamp: 0,
                timeDifference: '',
                // 时间戳
                givenTimestamp: null,
                // 给后台的时间
                newTime: null,
                // 数据
                newData: {},
                mch: {},

                showTemplate: [],
                isClickGroupBt: false, //是否为点击群按钮购买
                timeData: {},
                templates: [],
                page: null,
                controlList: [],
                useNav: false,
                goodsInfo: null,
                hotelData: {
                    // 弹框显示与隐藏
                    show: false,
                    // 时间列表
                    date_book: [],
                    num: 1
                },
                serveData: {
                    show: false,
                    service_book: [],
                    num: 1
                },
                shopmsg: null, //商品信息
                attr: [],
                shopItemInfo: {}, //存放要和选中的值进行匹配的数据
                goodsInfoNew: {}, //当规格选择完成时重新覆盖商品信息
                skutitlename: "", //提示用户例如：请选择温度，口味；或者提示用户已选择温度，口味
                skutitlenamelist: [], //存储规格标题
                skuId: "", //规格id
                selectArr: [], //存放被选中的值	selectArr: [], //存放被选中的值
                showSkuPopup: false, //控制选择商品类型弹窗的显示与隐藏
                finalmsg: null, //选取规格后的商品数量，以及是否为会员价格信息
                subIndex: [], //是否选中 因为不确定是多规格还是单规格，所以这里定义数组来判断
                shopimg: "", //选择商品规格时的商品图片
                value: 1, // sku选择的数量
                id: 0, // 商品id
                addressList: [],
                showGoodsShare: false,
                couponList: [],
                cardList: [],
                isLogin: false,
                submitType: "",

                countDown: [],
                ptId: -1, //团id
                cutPriceType: undefined
            };
        },

        computed: {
            getSeckillPriceOld() {
                if (!this.goodsInfo) return "";
                if (
                    this.goodsInfo.seckill_activity_arr &&
                    this.goodsInfo.seckill_activity_arr.use_attr === "1"
                ) {
                    return String(
                        this.goodsInfo.seckill_activity_arr.attr[0]?.seckill_price
                    );
                }
                return this.goodsInfo.seckill_activity_arr ?
                    this.goodsInfo.seckill_activity_arr.seckill_price :
                    0;
            },

            getSeckillPrice() {
                return (price) => {
                    if (!price) return [];
                    return price.split(".");
                };
            },

            pageCss() {
                if (this.page) {
                    let pageCss = JSON.parse(JSON.stringify(this.page.pageCss));
                    if (pageCss?.padding) delete pageCss.padding;
                    if (pageCss?.borderRadius) delete pageCss.borderRadius;
                    return pageCss;
                } else {
                    return "";
                }
            },
            skuText() {
                if (this.skuId != "") {
                    let str = [];
                    this.skuId.forEach((item) => {
                        str.push(item.attr_name);
                    });
                    return str.join(",");
                } else {
                    return this.$t("diy.sku");
                }
            }
        },
        mounted() {
            // uni.showLoading({
            //   title: this.$t("home.loading"),
            // });
            this.getDiySystemPages();
            this.getAddressList();
            if (this.goods_id) {
                this.id = this.goods_id;
                this.getGoodsDetail(this.goods_id);
                this.getDiscountsList();
            }

        },

        beforeDestroy() { //页面关闭时清除定时器  
            clearInterval(timers);
        },

        watch: {
            ptId(val, ovl) {
                if ((val > -1 && ovl == -1) || (val == -1 && ovl > -1)) {
                    this.getInfo(this.selectArr);
                }
            },
            isClickGroupBt(val) {
                this.getPriceNum(this.attr_list);
            },
            clearTimer(newVal) {
                if (newVal) {
                    clearInterval(timers);
                } else {
                    this.startTimer()
                }
            }
        },
        methods: {
            // 进店
            goStore() {
                console.log('this.mch.id', this.mch.id)
                uni.navigateTo({
                    url: `/mch_store/mchCommodity/mchCommodity?mch_id=${this.mch.id}`
                })
            },
            formatTime(seconds) {
                const days = Math.floor(seconds / (3600 * 24));
                const hours = Math.floor((seconds % (3600 * 24)) / 3600);
                const minutes = Math.floor((seconds % 3600) / 60);
                const remainingSeconds = seconds % 60;

                let result = '';
                if (days > 0) {
                    result += `${days} 天 `;
                }
                if (hours > 0) {
                    result += `${hours} 小时 `;
                }
                if (minutes > 0) {
                    result += `${minutes} 分钟 `;
                }
                if (remainingSeconds > 0 || result === '') {
                    result += `${remainingSeconds} 秒`;
                }

                return result;
            },
            // 定时器逻辑触发
            startTimer() {
                timers = setInterval(() => {
                    // 每三秒调取一下最新的下单数据
                    this.orderInformationFun()
                }, 2500);
            },
            orderInformationFun() {
                this.$allrequest.goods.orderInformation({
                    goods_id: this.goodsInfo.id,
                    time: this.newTime || 0
                }).then((res) => {
                    if (!res.code) {
                        this.newData = res.data
                        this.newTime = res.data ? res.data.created_at : 0
                        this.givenTimestamp = res.data ? res.data.created_at : 0

                        // 获取当前时间戳（秒）
                        this.currentTimestamp = Math.floor(Date.now() / 1000);
                        // 计算时间差
                        const differenceSeconds = this.currentTimestamp - this.givenTimestamp;

                        // 将时间差转换为时间格式并附上单位
                        this.timeDifference = this.formatTime(differenceSeconds);
                    } else {
                        return
                    }
                });
            },



            hasVersion(minVersion) {
                let current = uni.getStorageSync("SDKVersion");

                if (!this.$utils.compare(current, minVersion)) {
                    uni.showToast({
                        title: "当前版本不支持此功能",
                        icon: "none"
                    });
                }
            },
            openawemeuserprofile({
                detail
            }) {
                if (detail.errNo) {
                    uni.showToast({
                        title: detail.errMsg,
                        icon: "none"
                    });
                }
            },
            groupShowConfirm() {
                uni.previewImage({
                    current: this.goodsInfo.activityWechatRoom.qr_code,
                    urls: [this.goodsInfo.activityWechatRoom.qr_code]
                });
            },
            timeChange(e) {
                this.timeData = e;
            },
            get_history() {
                uni.navigateTo({
                    url: "/source/history/history?product_batch_id=" +
                        this.goodsInfo.product_batch_id
                });
            },

            formatNumber(n) {
                n = n.toString();
                return n[1] ? n : "0" + n;
            },

            countDownDataItem(endTime, startTime) {
                let currentTime = new Date().getTime(),
                    activeTime = endTime,
                    item = [],
                    is = 0; // 0距离结束 1距离开始

                if (currentTime < startTime && startTime - currentTime > 0) {
                    // 如果活动未开始，对时间进行处理
                    activeTime = startTime;
                    is = 1;
                }

                if (activeTime - currentTime > 0) {
                    // 如果活动未结束，对时间进行处理

                    let time = (activeTime - currentTime) / 1000;

                    // 获取天、时、分、秒
                    let day = parseInt(time / (60 * 60 * 24)),
                        hou = this.formatNumber(parseInt((time % (60 * 60 * 24)) / 3600)),
                        min = this.formatNumber(
                            parseInt(((time % (60 * 60 * 24)) % 3600) / 60)
                        ),
                        sec = this.formatNumber(
                            parseInt(((time % (60 * 60 * 24)) % 3600) % 60)
                        );

                    item = [day, hou, min, sec, is];
                } else {
                    item = [];
                    clearInterval(timer);

                    if (!is) {
                        this.countDownDataItem(endTime, startTime);
                    } else {
                        this.$utils.showModal("提示", "该活动已结束", false, () => {
                            uni.navigateBack();
                        });
                    }
                }

                this.countDown = item;
            },

            confirmBuy() {
                if (this.submitType == "buy") {
                    this.rightBuy();
                } else {
                    this.addCart();
                }
            },
            scrollToNode(e) {
                if (e.id == 0) {
                    uni.pageScrollTo({
                        duration: 300,
                        scrollTop: 0
                    });
                } else {
                    this.gotoPing(e.id);
                }
            },
            gotoPing(id) {
                const query = uni.createSelectorQuery().in(this);
                let selecter = "#" + id;
                query
                    .select(selecter)
                    .boundingClientRect((data) => {
                        let top = data.top;
                        if (this.pageScrollTop) {
                            top = top + this.pageScrollTop;
                        }
                        top = top - 100;
                        uni.pageScrollTo({
                            duration: 300,
                            scrollTop: top
                        });
                    })
                    .exec();
            },
            // 获取diy系统页面配置数据
            getDiySystemPages() {
                this.$allrequest.diyNew.getDiySystemPages({}, true).then((res) => {
                    uni.stopPullDownRefresh();
                    if (!res.code) {
                        let list = res.data.list;
                        let data = {};
                        let showTemplate = null;
                        if (!list.length) return;
                        list.forEach((d) => {
                            d.template = JSON.parse(d.template);
                            if (d.template.system_type == "goodsDetail") {
                                data = d;
                            }
                            if (d.template.system_type == "showGoodsDetail") {
                                showTemplate = d;
                            }
                        });

                        if (showTemplate) this.showTemplate = showTemplate.template.templates;
                        if (!data?.id) return;
                        this.page = data.template;
                        let arr = [
                            // {
                            //   comName: "goodsRecommend",
                            //   name: "商品详情页面-商品推荐",
                            // },
                            {
                                comName: "goodsRichText",
                                name: this.$t("diy.detail")
                            }
                        ];
                        data.template.templates.push(...arr);

                        // 获取评价所在索引，插入拼团模块
                        let commentIndex = data.template.templates.findIndex(
                            (item) => item.comName == "goodsShopEntry"
                        );
                        // 插入拼团商品模块
                        data.template.templates.splice(commentIndex, 0, {
                            comName: "goodsPt"
                        });
                        this.templates = data.template.templates;
                        res.data.controls = JSON.parse(res.data.controls);
                        this.controlList = res.data.controls;
                        let [footNav] = this.controlList.filter((d) => {
                            return d.show_type == "nav";
                        });
                        if (footNav && footNav.is_show) {
                            this.useNav = true;
                        }
                    }
                });
            },
            // 获取商品详情数据
            getGoodsDetail(id) {
                uni.showLoading({
                    title: this.$t("facePay.requesting")
                });

                let {
                    activity_new_user_id,
                    activity_cut_price_id,
                    is_seckill
                } = this,
                params = {
                    id,
                    activity_new_user_id,
                    activity_cut_price_id,
                    is_seckill
                };

                if (this.is_pt) {
                    params.is_pt = "1";
                }

                this.shopmsg = null;

                this.$allrequest.goods
                    .goodsDetails(params)
                    .then((res) => {
                        if (!res.code) {
                            this.mch = res.data.mch

                            console.log('this.mch', this.mch)
                            res.data.attr = JSON.parse(res.data.attr);
                            if (res.data.video_url) {
                                res.data.pic_list.unshift({
                                    type: "video",
                                    pic_url: res.data.video_url
                                });
                            }

                            if (res.data.seckill_activity_arr) {
                                let {
                                    end_time,
                                    start_time
                                } = res.data.seckill_activity_arr;

                                clearInterval(timer);
                                this.countDownDataItem(end_time * 1000, start_time * 1000);
                                timer = setInterval(() => {
                                    this.countDownDataItem(end_time * 1000, start_time * 1000);
                                }, 1000);
                            }
                            this.showUnion = res.data.is_league;
                            this.send_price = (
                                res.data.min_price * res.data.goods_send_profit
                            ).toFixed(2);
                            this.take_price = (
                                res.data.min_price * res.data.goods_take_profit
                            ).toFixed(2);
                            this.goodsInfo = JSON.parse(JSON.stringify(res.data));
                            this.shopmsg = res.data;

                            this.orderInformationFun()
                            this.startTimer(); // 组件挂载时启动定时器

                            // 过滤预约时间
                            this.filterYuyueDate(res.data);
                            // 记录浏览历史
                            this.recordBrowse();

                            // 预处理sku
                            var attr_group_list = res.data.attr_group_list;
                            for (var i = 0; i < attr_group_list.length; i++) {
                                for (var j = 0; j < attr_group_list[i].attr_list; j++) {
                                    attr_group_list[i].attr_list[j].ischeck = false;
                                }
                            }

                            this.swiperlength = res.data.pic_list.length;
                            this.carouselmap = true;

                            if (this.shopmsg.pic_list.length != 0) {
                                if (this.shopmsg.pic_list[0].type != "video") {
                                    this.shopimg = this.shopmsg.pic_list[0].pic_url;
                                } else {
                                    if (this.shopmsg.pic_list.length > 1) {
                                        this.shopimg = this.shopmsg.pic_list[1].pic_url;
                                    }
                                }
                            }

                            for (var i of this.shopmsg.attr) {
                                var sp = "";
                                for (var j of i.attr_list) {
                                    sp += j.attr_id + "_";
                                }
                                if (sp.length > 0) {
                                    sp = sp.substr(0, sp.length - 1);
                                }
                                this.shopItemInfo[sp] = i;
                            }
                            for (var m of this.shopmsg.attr_group_list) {
                                this.skutitlenamelist.push(m.attr_group_name);
                            }
                            this.checkItem();
                            this.$nextTick(() => {
                                if (res.data.product_type === 7) return;
                                this.getSku();
                                try {
                                    const query = uni.createSelectorQuery().in(this);
                                    // 商品
                                    let goodsInfo = "#goodsAttribute";
                                    if (query.select(goodsInfo)) {
                                        query
                                            .select(goodsInfo)
                                            .boundingClientRect((data) => {
                                                this.$emit("goodsBlockLocalData", {
                                                    t: data.top,
                                                    h: data.height
                                                });
                                            })
                                            .exec();
                                    }
                                    // 评论
                                    const query2 = uni.createSelectorQuery().in(this);
                                    let goodsEvaluate = "#goodsEvaluate";
                                    if (query2.select(goodsEvaluate)) {
                                        query2
                                            .select(goodsEvaluate)
                                            .boundingClientRect((data) => {
                                                this.$emit("goodsEvaluateLocalData", {
                                                    t: data.top,
                                                    h: data.height
                                                });
                                            })
                                            .exec();
                                    }

                                    // 详情
                                    let selecter = "#goodsRichText";
                                    const query3 = uni.createSelectorQuery().in(this);
                                    if (query3.select(selecter)) {
                                        query3
                                            .select(selecter)
                                            .boundingClientRect((data) => {
                                                this.$emit("goodsRichTextLocalData", {
                                                    t: data.top,
                                                    h: data.height
                                                });
                                            })
                                            .exec();
                                    }
                                } catch (err) {}

                                // 预约商品进入
                                if (res.data.product_type == 2 && this.date) {
                                    let index = this.serveData.service_book.data.findIndex(
                                        (el) => el.date === this.date
                                    );

                                    setTimeout(() => {
                                        this.serveData.show = true;
                                        this.$refs.ServePopup.clickDateScrollItem(index);
                                    }, 500);
                                }
                            });
                            uni.hideLoading();
                        } else {
                            uni.showToast({
                                title: res.msg,
                                duration: 2000,
                                icon: "none"
                            });
                            setTimeout(() => {
                                // uni.navigateBack();
                                this.$utils.goBack();
                            }, 1500);
                        }
                    })
                    .catch(() => {
                        setTimeout(() => {
                            // uni.navigateBack();
                            this.$utils.goBack();
                        }, 1500);
                    });
            },
            // 获取用户地址列表
            async getAddressList() {
                // 判断是否登录
                const isLogin = this.$utils.isLogin(false);
                if (!isLogin) return;
                try {
                    const res = await this.$allrequest.user.address_list();
                    this.addressList = res.data.list;
                } catch (e) {}
            },
            // 获取优惠列表
            async getDiscountsList() {
                try {
                    const res = await this.$allrequest.goods.getGoodYouHui({
                        id: this.goods_id
                    });
                    if (res.code == 0) {
                        this.cardList = res.data.data;
                        this.couponList = res.data.coupon;
                    }
                } catch (e) {}
            },
            // 获取当前年月日, 判断预约时间
            getDate() {
                let date = new Date();
                let y = date.getFullYear();
                let m = date.getMonth() + 1;
                let d = date.getDate();
                const res = uni.getSystemInfoSync();
                if (res.system.indexOf("iOS") > -1) {
                    return `${y}/${m}/${d}`;
                } else {
                    return `${y}-${m}-${d}`;
                }
            },
            filterYuyueDate(data) {
                // 获取当前时间
                let currentDate = this.getDate();
                let filterData = [];

                // 获取当前时间
                let date = new Date();
                let hh = date.getHours();
                let ff = date.getMinutes();
                let currentTime = `${hh}:${ff}`;
                let currentDateTime = `${currentDate} ${currentTime}`;

                switch (data.product_type) {
                    // 酒店预约
                    case 1:
                        this.hotelData.num = this.value;
                        // 根据日期过滤
                        // filterData = data.date_book.date_book.filter((item) => {
                        filterData = data.num.filter((item) => {
                            if (
                                new Date(item.date).getTime() >= new Date(currentDate).getTime()
                            ) {
                                // item.price = data.price;
                                return item;
                            }
                        });
                        // 赋值酒店组件时间列表
                        this.hotelData.date_book = Object.assign(data.date_book, {
                            date_book: filterData
                        });
                        break;

                        // 服务预约
                    case 2:
                        this.serveData.num = this.value;
                        // 根据日期过滤
                        filterData = data.service_book.data.filter((item) => {
                            // 日期大于等于当前时间且有二级分类
                            if (
                                new Date(item.date).getTime() >=
                                new Date(currentDate).getTime() &&
                                item.time.length
                            ) {
                                return item;
                            }
                        });

                        if (!filterData.length) break;
                        // 根据二级时间段过滤 11:00-14:00
                        let newTime = filterData[0].time.filter((item) => {
                            if (
                                new Date(`${currentDate} ${item.end_time}`).getTime() >
                                new Date(currentDateTime).getTime() &&
                                item.times.length
                            ) {
                                return item;
                            }
                        });

                        if (!newTime.length) {
                            filterData.splice(0, 1);
                        } else {
                            filterData[0].time = newTime;

                            // 过滤三级时间 10:00-14:00
                            let newTimes = filterData[0].time[0].times.filter((item) => {
                                let timeArr = item.time.split("-");

                                // 当前时间向前提15分钟,如果开始时间还大于当前时间则可以预约   也表示开始15分钟后可以预约
                                if (
                                    new Date(`${currentDate} ${timeArr[0]}`).getTime() >
                                    new Date(currentDateTime).getTime() - 15 * 60 * 1000
                                ) {
                                    return item;
                                }
                            });

                            if (newTimes.length) {
                                filterData[0].time[0].times = newTimes;
                            } else {
                                filterData[0].time.splice(0, 1);
                                if (!filterData[0].time.length) {
                                    filterData.splice(0, 1);
                                }
                            }
                        }
                        this.serveData.service_book = Object.assign(data.service_book, {
                            data: filterData
                        });
                        break;
                    default:
                        break;
                }
            },
            // 点击预约按钮
            clickYuyue() {
                switch (this.shopmsg.product_type) {
                    // 酒店
                    case 1:
                        if (this.hotelData.date_book.date_book?.length) {
                            // this.hotelData.show = true;
                            this.$refs.timePopup.showPopup();
                        } else {
                            uni.showToast({
                                title: this.$t("diy.noTime"),
                                icon: "none"
                            });
                        }
                        break;
                        // 服务
                    case 2:
                        if (this.serveData.service_book.data?.length) {
                            this.serveData.show = true;
                            // this.$refs.ServePopup.show = true;
                        } else {
                            uni.showToast({
                                title: this.$t("diy.noTime"),
                                icon: "none"
                            });
                        }
                        break;
                    default:
                        break;
                }
            },
            //处理数据
            checkItem() {
                var option = this.shopmsg.attr_group_list;
                var result = []; //定义数据存储被选中的值)
                for (let i = 0; i < option.length; i++) {
                    result[i] = this.selectArr[i] ? this.selectArr[i] : "";
                }
                for (let i = 0; i < option.length; i++) {
                    var last = result[i];
                    for (var k = 0; k < option[i].attr_list.length; k++) {
                        result[i] = option[i].attr_list[k].attr_id;
                        option[i].attr_list[k].isShow = this.isMay(result);
                    }
                    result[i] = last;
                }
                this.shopmsg.attr_group_list = [];
                this.$set(this.shopmsg, "attr_group_list", option);

                this.getInfo(this.selectArr);
            },
            // 判断库存是否为0
            isMay(result) {
                for (var i in result) {
                    if (result[i] == "") {
                        return true;
                    }
                }
                result = result.join("_");
                if (!this.shopItemInfo[result]) {
                    return false;
                }
                return this.shopItemInfo[result].num == 0 ? false : true;
            },
            // 预约时间数据发生改变
            hotelDataChange(val) {
                this.hotelData = val;
            },
            //
            timeConfirm(e) {
                if (this.shopmsg.product_type == 1) {
                    this.hotelData.num = e.num;
                }
                if (this.shopmsg.product_type == 2) {
                    this.serveData.num = e.num;
                }
                this.rightBuy(e.list);
            },
            // 酒店提交预约
            submitHotel(list) {
                this.rightBuy(list);
            },
            // sku选择弹框数量选择回调
            setSelectNum(e) {
                this.value = e;
            },
            //立即购买, 预约提交
            rightBuy(list) {
                this.submitType = "buy";
                let submitOrder = [],
                    {
                        product_type
                    } = this.shopmsg,
                    {
                        attr_group_list
                    } = this.goodsInfo;

                // 判断商品类型
                switch (product_type) {
                    case 1:
                        submitOrder = [{
                            product_type,
                            mch_id: this.shopmsg.mch ? this.shopmsg.mch.id : 0,
                            goods_list: [{
                                goods_id: this.shopmsg.id,
                                num: this.hotelData.num,
                                attr: [{
                                    attr_id: attr_group_list[0].attr_list[0].attr_id,
                                    attr_group_id: attr_group_list[0].attr_group_id
                                }]
                            }],

                            list
                        }];
                        uni.navigateTo({
                            url: "/order/order-submit/order-submit?submit=" +
                                JSON.stringify(submitOrder)
                        });
                        break;
                    case 2:
                        submitOrder = [{
                            product_type,
                            mch_id: this.shopmsg.mch ? this.shopmsg.mch.id : 0,
                            goods_list: [{
                                goods_id: this.shopmsg.id,
                                num: this.serveData.num,
                                attr: this.attr
                            }],
                            list
                        }];
                        uni.navigateTo({
                            url: "/order/order-submit/order-submit?submit=" +
                                JSON.stringify(submitOrder)
                        });
                        break;
                    default:
                        // 如果没有选择规格商品则打开弹框
                        if (!this.$refs.skuPopup.showSkuPopup) {
                            // 点击立即拼团时已显示规格弹框，只有点击单独购买才能走到这里，如果时拼团商品这视为单独购买，更改ptId-1为了单独购买状态，为了重新获取普通商品规格信息
                            if (this.goodsInfo.pt_activity && this.is_pt) {
                                this.ptId = -1;
                            }
                            if (this.activity_cut_price_id) {
                                this.cutPriceType = list;
                            }
                            this.$nextTick(() => {
                                this.$refs.skuPopup.showPopup();
                            });

                            return;
                        }
                        if (this.finalmsg == "" || this.finalmsg == undefined) {
                            uni.showToast({
                                title: this.$t("diy.sku"),
                                icon: "none"
                            });
                            return;
                        } else {
                            if (!uni.getStorageSync("token")) {
                                let routes = getCurrentPages();
                                this.$store.commit(
                                    "setNoLoginTabarPath",
                                    routes[routes.length - 1].$page.fullPath
                                );
                                this.$store.commit("setRouteType", "redirectTo");

                                uni.redirectTo({
                                    url: "/login/login/login_page"
                                });
                                return;
                            }

                            if (
                                this.value > this.finalmsg.num ||
                                this.value > this.shopmsg.num
                            ) {
                                uni.showToast({
                                    title: this.$t("diy.stock"),
                                    icon: "none"
                                });
                                return;
                            }
                            submitOrder = [{
                                product_type,
                                mch_id: this.shopmsg.mch ? this.shopmsg.mch.id : 0,
                                goods_list: [{
                                    goods_id: this.shopmsg.id,
                                    num: this.value,
                                    attr: this.attr,
                                    videoId: this.videoId
                                }]
                            }];
                            // 如果选择拼团提交订单预览携带拼团id 0表示开团 >0表示拼团
                            let url = `/order/order-submit/order-submit?submit=${JSON.stringify(
              submitOrder
            )}`;

                            // 优先使用当前选择团id，备用邀请团id
                            if (this.ptId > -1 || this.$root.pt_number) {
                                url += `&pt_number=${this.ptId || this.$root.pt_number}`;
                            }

                            let {
                                cutPriceType,
                                activity_cut_price_id
                            } = this;

                            if (cutPriceType === 2) {
                                submitOrder[0].activity_cut_price_id = activity_cut_price_id;
                                url += `&activity_cut_price_id=${activity_cut_price_id}`;
                            }

                            // 秒杀传参
                            if (this.is_seckill) {
                                url += `&is_seckill=1`;
                            }

                            // 是群商品，切选择了群价格
                            if (
                                this.shopmsg.activityWechatRoom?.inRoom &&
                                this.isClickGroupBt
                            ) {
                                url += `&activity_wechat_room_id=${this.shopmsg.activityWechatRoom.id}`;
                            }

                            uni.navigateTo({
                                url
                            });

                            this.$refs.skuPopup.showSkuPopup = false;
                        }

                        break;
                }
            },
            toAddCart() {},
            //添加到购物车
            addCart() {
                this.submitType = "addCart";
                if (!this.$refs.skuPopup.showSkuPopup) {
                    this.$refs.skuPopup.showPopup();
                    return;
                }
                if (this.finalmsg == "" || this.finalmsg == undefined) {
                    uni.showToast({
                        title: this.$t("diy.sku"),
                        icon: "none"
                    });
                    return;
                }

                if (this.value > this.finalmsg.num || this.value > this.shopmsg.num) {
                    uni.showToast({
                        title: this.$t("diy.stock"),
                        icon: "none"
                    });
                    return;
                }

                this.$allrequest.goods
                    .addCart({
                        goods_id: this.id,
                        attr: JSON.stringify(this.attr),
                        num: this.value
                    })
                    .then((res) => {
                        this.show = !this.show;
                        if (res.code == 0) {
                            uni.showToast({
                                title: res.msg,
                                icon: "none"
                            });
                            // 加购成功后，关闭sku弹框
                            this.closeSkuPopup();
                        } else {
                            uni.showToast({
                                title: res.msg,
                                icon: "none"
                            });
                        }
                    });
            },
            // 预约时间数据发生改变
            serveDataChange(val) {
                this.serveData = val;
            },
            // 服务提交预约
            serveSubmit(formData) {
                this.rightBuy(formData);
            },
            //记录浏览记录
            recordBrowse() {
                var params = {
                    id: this.id,
                    type: 0 //1：商户，0：商品
                };
                this.$allrequest.goods.browse(params).then((res) => {});
            },
            // 获取sku属性
            getSku() {
                let goods_sku = this.$refs.goods_sku;
                if (goods_sku) {
                    goods_sku[0].getInfo();
                }
            },
            selectAddressEnd() {
                let goods_sku = this.$refs.goods_sku;
                if (goods_sku) {
                    goods_sku[0].updateAddress();
                }
            },
            //获取选定的值
            getInfo(item) {
                var checked = item.join("_");
                if (this.shopItemInfo[checked]) {
                    this.goodsInfoNew = this.shopItemInfo[checked];
                    this.skutitlename =
                        this.$t("common.choosed") +
                        "：" +
                        this.shopItemInfo[checked].supplier_price;
                    this.skuId = this.shopItemInfo[checked].attr_list;
                } else {
                    this.goodsInfoNew = {};
                    var skutitle = [];
                    for (var i = 0; i < this.skutitlenamelist.length; i++) {
                        if (this.skutitlenamelist[i]) {
                            skutitle.push(this.skutitlenamelist[i]);
                        }
                    }
                    this.skutitlename =
                        this.$t("common.noChoose") + " " + skutitle.toString(",");
                    this.skuId = "";
                }
                if (this.skuId) {
                    this.arrt_list = [];
                    for (var i = 0; i < this.skuId.length; i++) {
                        this.arrt_list.push(this.skuId[i].attr_id);
                    }
                    this.arrt_list.join(",");
                    this.getPriceNum(this.arrt_list);
                }
            },
            //通过选取规格获取该规格下的商品准确价格
            getPriceNum(arrt_list) {
                if (!arrt_list || !arrt_list.length) return;
                if (this.activity_new_user_id || this.isClickGroupBt) {
                    let ids = arrt_list.join(","),
                        attr = this.shopmsg.attr;

                    for (let i = 0; i < attr.length; i++) {
                        let item = attr[i].attr_list.map((el) => el.attr_id).join(",");
                        if (ids === item) {
                            this.finalmsg = attr[i];
                            break;
                        }
                    }
                    return;
                }

                var params = {
                    is_seckill: this.is_seckill,
                    goods_id: this.shopmsg.id,
                    attr_list: arrt_list,
                    number: this.value
                };

                // 如果是拼团商品更改请求接口添加拼团属性
                let requestName = "goodsAttrInfo";
                if (this.goodsInfo.pt_activity && this.ptId > -1) {
                    requestName = "ptGoodsAttrInfo";
                    params.is_pt = 1;
                }

                try {
                    params.attr_list = JSON.stringify(params.attr_list);
                    this.$allrequest.goods[requestName](params, true).then((res) => {
                        if (res.code == 0) {
                            this.finalmsg = res.data;

                            // 对比砍价数据
                            if (this.activity_cut_price_id) {
                                let {
                                    finalmsg,
                                    goodsInfo
                                } = this, {
                                    cutGoods
                                } = goodsInfo;
                                let {
                                    num,
                                    price
                                } = this.comparisonAttr(
                                    cutGoods.attr,
                                    JSON.parse(params.attr_list)
                                );
                                finalmsg.num = num;
                                finalmsg.min_price = price;
                            }
                        }
                    });
                } catch (e) {}
            },
            comparisonAttr(attrList, str) {
                attrList = JSON.parse(attrList);
                let el = null;

                let str1 = str.join(",");
                for (let i = 0; i < attrList.length; i++) {
                    let str2 = attrList[i].attr_list.map((el) => el.attr_id).join(",");
                    if (str1 === str2) {
                        el = attrList[i];
                        break;
                    }
                }

                return el;
            },
            //显示和关闭商品规格内容
            selectSku() {
                this.$refs.skuPopup.showPopup();
            },
            // 关闭sku弹框
            closeSkuPopup() {
                this.$refs.skuPopup.hidePopup();
            },
            // 选择sku回调
            selectPushData(e) {
                let {
                    id,
                    pindex,
                    index,
                    disable,
                    attr_group_id
                } = {
                    ...e
                };
                this.pushData(id, pindex, index, disable, attr_group_id);
            },
            pushData(id, pindex, index, disable, attr_group_id) {
                if (!disable) {
                    return "";
                }
                if (this.selectArr[pindex] != id) {
                    this.selectArr[pindex] = id;
                    this.subIndex[pindex] = index;
                    this.skutitlenamelist[pindex] = "";
                    this.attr[pindex] = {
                        attr_id: id,
                        attr_group_id: attr_group_id
                    };
                }
                this.checkItem();
            },
            // 跳转我的地址列表
            gotoMyAddress() {
                if (this.addressList.length) {
                    this.$refs.sendPopup.showPopup();
                } else {
                    this.$utils.toUrl("/user/my/addressmanage?is_order=1");
                }
            },
            // 展示优惠券弹框
            couponPopupShow() {
                if (this.couponList.length) this.$refs.couponPopup.showPopup();
            },
            // 展示赠送的核销卡
            activePopupShow() {
                if (this.goodsInfo.verify_card_id.length)
                    this.$refs.activePopup.showPopup();
            },
            // 点击拼团
            onClickPt(item) {
                this.submitType = "buy";
                this.ptId = item.id;
                this.$refs.skuPopup.showPopup();
            },
            // 点击开团
            onPt() {
                this.submitType = "buy";
                this.ptId = 0;
                this.$refs.skuPopup.showPopup();
            },
            // 立即购买
            onGroup(isGroup) {
                this.isClickGroupBt = !!isGroup;

                this.getPriceNum(this.arrt_list);

                // 可享受群优惠价
                if (this.shopmsg.activityWechatRoom.inRoom) {
                    // 显示规格选择
                    this.submitType = "buy";

                    this.$refs.skuPopup.showPopup();
                }

                // 未登录 ｜｜ 未进入群
                else {
                    // 未登录跳转登录
                    if (!uni.getStorageSync("token")) {
                        let routes = getCurrentPages();
                        if (routes.length > 0) {
                            this.$store.commit(
                                "setNoLoginTabarPath",
                                routes[routes.length - 1].$page.fullPath
                            );
                            this.$store.commit("setRouteType", "redirectTo");
                        }
                        uni.redirectTo({
                            url: "/login/login/login_page"
                        });
                    } else {
                        this.$refs.GroupPromptPopup.switchShowPopup();
                    }
                }
            },

            async collect() {
                let {
                    goodsInfo
                } = this;
                const res = await this.$allrequest.goods.favoriteGoods({
                        id: this.goods_id,
                        type: 0
                    },
                    true
                );
                if (res.code == 0) {
                    uni.showToast({
                        icon: "none",
                        title: goodsInfo.is_favorite ? "已取消收藏" : "收藏成功"
                    });
                    this.$set(goodsInfo, "is_favorite", goodsInfo.is_favorite ? 0 : 1);
                }
            },
            goPriceReduction() {
                uni.requestSubscribeMessage({
                    tmplIds: this.goodsInfo.template_id,
                    success: () => { // 使用箭头函数捕获上下文
                        this.lowering();
                    },
                });
            },
            async lowering() {
                let {
                    goodsInfo
                } = this;
                const res = !goodsInfo.is_lowering ? await this.$allrequest.goods.getPriceDesire({
                        id: this.goods_id,
                        type: 0
                    },
                    true
                ) : await this.$allrequest.goods.cancelPriceDesire({
                        id: this.goods_id,
                        type: 0
                    },
                    true
                );
                if (res.code == 0) {
                    uni.showToast({
                        icon: "none",
                        title: goodsInfo.is_lowering ? "取消降价通知成功" : "订阅降价通知成功"
                    });
                    this.$set(goodsInfo, "is_lowering", goodsInfo.is_lowering ? 0 : 1);
                }
            }
        },

        onUnload() {
            clearInterval(timer);
        },
    };
</script>

<style lang="scss" scoped>
    .storeNext {
        width: 750rpx;
        height: 108px;
        background: #FFFFFF;
        padding: 24rpx;

        .bg {
            display: flex;
            align-items: center;
            padding: 24rpx;
            background: linear-gradient(180deg, #F8F8F8 0%, #FEFDFD 100%);
            border-radius: 20rpx 20rpx 20rpx 20rpx;

            .content {
                margin-left: 18rpx;
                width: 378rpx;

                .name {
                    font-weight: 600;
                    font-size: 30rpx;
                    color: #262626;
                }

                .address {
                    font-weight: 400;
                    font-size: 24rpx;
                    color: #8C8C8C;
                    margin-top: 10rpx;
                }
            }

            .btn {
                background: #F0250E;
                border-radius: 10rpx 10rpx 10rpx 10rpx;
                font-weight: 600;
                font-size: 26rpx;
                color: #FFFFFF;
                padding: 12rpx 25rpx;
            }
        }
    }

    .diy-page {
        width: 100%;
        overflow-y: auto;
        position: relative;

        .diy-page-bg {
            width: 100%;
            height: 100%;
            z-index: -1;
            position: absolute;
            left: 0;
            top: 0;
            background-color: #f2f2f2;
        }
    }

    .no-scroll {
        overflow: hidden;
        height: 100vh;
    }

    .useFoot {
        padding-bottom: calc(300rpx + constant(safe-area-inset-bottom));
        padding-bottom: calc(300rpx + env(safe-area-inset-bottom));
    }

    .seckill {
        position: relative;
        height: 130rpx;

        .seckillBg {
            position: absolute;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
        }

        .seckillCon {
            position: relative;
            z-index: 2;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 24rpx;
            height: 100%;
            color: #fff;

            .let {
                flex: 1;
                overflow: hidden;
                display: flex;
                align-items: center;
                font-size: 24rpx;
            }

            .price1 {
                display: flex;
                align-items: flex-end;
                font-weight: bold;

                &:before {
                    content: "￥";
                    font-size: 34rpx;
                }

                view {
                    font-size: 56rpx;
                    line-height: 1;
                }
            }

            .price2 {
                position: relative;
                margin: 0 10rpx;

                &:after {
                    content: "";
                    position: absolute;
                    left: 0;
                    top: 50%;
                    width: 100%;
                    height: 1px;
                    background: #fff;
                }
            }

            .price2,
            .num {
                margin-top: 24rpx;
            }

            .rig {
                min-width: 226rpx;
                margin-left: 10rpx;
                display: flex;
                flex-direction: column;
                justify-content: center;
            }

            .countDown {
                display: flex;
                align-items: center;
                justify-content: center;
                padding-bottom: 12rpx;
                font-size: 26rpx;

                .s1 {
                    font-weight: 400;
                }

                .s2 {
                    margin-left: 10rpx;
                    font-weight: 600;
                }
            }

            .line {
                position: relative;
                background: #f0250e;
                border-radius: 32px;
                height: 28rpx;
                width: 226rpx;
            }

            .lineCon {
                position: absolute;
                z-index: 3;
                left: 0;
                top: 0;
                width: 100%;
                height: 100%;
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 20rpx;
            }

            .lineBox {
                position: absolute;
                top: 0;
                height: 100%;
                background: #ff5c26;
                border-radius: 32px;
            }
        }
    }

    .footerNav {
        position: fixed;
        left: 0;
        bottom: 0;
        width: 100%;
        z-index: 10;
        background: #fff;
        padding-bottom: 0;
        padding-bottom: env(safe-area-inset-bottom);
        padding-bottom: constant(safe-area-inset-bottom);

        &.round {
            button {
                border-radius: 32px;
            }
        }

        button {
            margin: 12rpx 36rpx;
            color: #fff;

            &:after {
                display: none;
            }
        }
    }
</style>